package com.glance.browser.repository;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import com.glance.browser.domain.History;

@Transactional(readOnly = true)
public interface HistoryRepository extends JpaRepository<History, Long>  {

	@Query("from History h where h.knowledgeClass = :knowledgeClass")
	public Page<History> findByKnowledgeClassId(@Param("knowledgeClass") Long knowledgeClassId, Pageable pageable);
	
	@Query("from History h where h.author = :author")
	public Page<History> findByChangeAuthor(@Param("author") String author, Pageable pageable);

	@Modifying
	@Query("delete from History where changeId > :changeId")
	public void deleteAllAfter(@Param("changeId") long changeId);
}
